import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Lucky
 * Break file path in directory and filename
 * @Change1: Stores the complete directory name
 *
 */
public class BreakFileDir {
	
	Connection conn=null;
	
	private String fid="";
	private String filepath="";
	
	public void readFile()
	{
		String query= "SELECT * FROM file_list";
		try {
				Statement stmt=conn.createStatement();
				stmt.execute(query);
				ResultSet res=stmt.getResultSet();
				while(res.next())
				{
					fid=res.getString("fid");
					filepath=res.getString("file");
					createObject();
				}
				if(stmt != null)
					stmt.close();
		}
		catch (SQLException e) 
		{
				e.printStackTrace();
		}
	}
	
	public void createObject()
	{
		int index=filepath.lastIndexOf("/");
		String fname=filepath.substring(index+1).trim();
		//String dir=filepath.substring(0, index).trim();
		String dir =filepath;//@@I want compplet path
		
		try 
		{
			String query="Insert into fname_fdir values ('"+fid+"','"+fname+"','"+dir+"')";
			System.out.println("query="+query);
			Statement stmt=conn.createStatement();
			stmt.executeUpdate(query);
		}
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		BreakFileDir bfd=new BreakFileDir();
		bfd.conn=(new db_conn()).connect("2jboss", "root", "123");
		bfd.readFile();
	}

}
